/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package Controlador;

import Conexion.Servidor;
import Dominio.Tank;
import java.awt.Graphics;
import java.util.LinkedList;
import javax.swing.ImageIcon;

/**
 *
 * @author Sebastian
 */
public class Controlador extends javax.swing.JPanel {
    
    ImageIcon stage = new ImageIcon(getClass().getResource("../Imagenes/Stage/stage.gif"));
    private LinkedList <Tank> lstTank= new LinkedList();
    private Servidor s;
    private int [] provicional;
    /**
     * Creates new form Controlador
     */
    public Controlador() {
        initComponents();
    }
    
    public void recibir(String [] rutasTank){
        Tank t = new Tank(10, 10, 36, 36, rutasTank);
        this.lstTank.add(t);
        this.s = new Servidor();
        Thread hilo = new Thread(this.s);
        hilo.start();
    }

    @Override
    public void paintComponent(Graphics g) {
        super.paintComponent(g);
        g.drawImage(this.stage.getImage(), 0, 0, this.getWidth(), this.getHeight(), this);
        if (!this.lstTank.isEmpty()) {
            for (int i = 0; i < this.lstTank.size(); i++) {
            g.drawImage(this.lstTank.get(i).getImagen().getImage(), this.lstTank.get(i).getX(), 
                    this.lstTank.get(i).getY(), this.lstTank.get(i).getAncho(), this.lstTank.get(i).getAlto(), this);
            }
        }
        this.provicional= this.s.getA();
        if (this.provicional[0]!=0){
          this.lstTank.get(0).setX(this.provicional[0]);  
          this.lstTank.get(0).setY(this.provicional[1]); 
          this.lstTank.get(0).girar(this.provicional[2]);
        }
        
        
        repaint();
    }
    
    

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 400, Short.MAX_VALUE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 300, Short.MAX_VALUE)
        );
    }// </editor-fold>//GEN-END:initComponents
    // Variables declaration - do not modify//GEN-BEGIN:variables
    // End of variables declaration//GEN-END:variables
}
